﻿using SqliteManager.SQLite3;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Globalization;
using System.Linq;
using System.Text;

namespace SqliteManager
{
    public class SQLiteSetting
    {
        public string Path;
        public string key;
    }

    public class AssetInfo
    {
        public string AssetID = "TestT01";
        public string ProjectID = "Test";
        public string Tags = "FFF;DDD;SSS;";
    }

    public class TagSetting
    {
        public int TagID = 1;
        public string TagName = "Nature";
    }

    class Program
    {
        static void Main(string[] args)
        {

            DateTime dt = DateTime.ParseExact("2020/8/7_14:09:52", "yyyy/M/d_HH:mm:ss", CultureInfo.CurrentCulture);
            Console.WriteLine(dt.ToString());

            Sqlite3DataBase db = new Sqlite3DataBase(@"E:\Node_Project\LibServer\LibMainIndex3.db");
            Stack<string> ss = new Stack<string>();
            ss.Push("TagID");
            ss.Push("TagName");
            ss.Push("DATE");
            ss.Push("GUID");
            string sql = DataBaseWriter.GetInsertSQL(new TagSetting(), ss);
            Console.WriteLine(sql);
            sql = "INSERT INTO 'TagSetting' " + sql + ";";
            Console.WriteLine(sql);
            db.ExecuteQuery(sql);
            Console.ReadKey();
        }

        static void TestSQLDirectly()
        {
            string sql = $"INSERT INTO 'TagSetting' (TagID,TagName,GUID) VALUES(1,'Root','{Guid.NewGuid().ToString()}');";
            Sqlite3DataBase db = new Sqlite3DataBase(@"E:\Node_Project\LibServer\LibMainIndex3.db");
            db.ExecuteQuery(sql);
        }

        static void TestReader()
        {
            Sqlite3DataBase db = new Sqlite3DataBase(@"E:\Node_Project\LibServer\LibMainIndex3.db");
            AssetInfo ai = db.ReadObject<AssetInfo>("Assets", "AssetID='TestT02'");
            Console.WriteLine(ai.ToDataString());
        }

        static void TestInsert()
        {
            Sqlite3DataBase db = new Sqlite3DataBase(@"E:\Node_Project\LibServer\LibMainIndex3.db");
            SQLiteDataReader r = db.ExecuteQuery("select name from sqlite_master where type='table' order by name;");
            while (r.Read())
            {
                Console.WriteLine(r.GetString(0));
            }
            Stack<string> ss = new Stack<string>();
            ss.Push("AssetID");
            ss.Push("ProjectID");
            ss.Push("Tags");
            string sql = DataBaseWriter.GetInsertSQL(new AssetInfo(), ss);
            Console.WriteLine(sql);
            sql = "INSERT INTO 'Assets' " + sql + ";";
            Console.WriteLine(sql);
            db.ExecuteQuery(sql);

            Console.WriteLine(ConfigManager<SQLiteSetting>.Data.Path);
        }
    }
}
